﻿#ifndef CLogOper_H
#define CLogOper_H
/********************************************************************************
** @ Date:2024/04/09
** @ Author: HanJiaXin
** @ Description:日志单例类
** @ Version:1.0.0
** @ ClassName:CLogOper
** @ Fun:
********************************************************************************/
#include <QString>
#include <QLibrary>
#include <QObject>

enum ELogType
{
	enWorkInfo=1,//系统信息
	enAlarmRecovery,//报警恢复
	enProcessAlarm,//工艺报警
	enSysAlarm,//系统异常报警
	enDevAlarm,//设备故障
};

struct SExecLog
{
	QString        m_sDevName;			//设备名
	QString        m_sFuncName;			//模块名 可以是算法模块、PLC模块等等
	QString        m_sDescriptionl;     //操作描述
	int            m_nAlarmLevel;       //报警等级

	SExecLog()
	{
		m_sDevName = QString::fromLocal8Bit("系统");
		m_sDescriptionl = "";
		m_sFuncName = QString::fromLocal8Bit("日志信息");
		m_nAlarmLevel = 0;
	}
};

typedef void(*AddMsg)(QString sModuleName, QString sDeviceName, QString sFuncName, int nLevel, QString sLog);
typedef QWidget*(*CreateLogWidget)(QString sModuleName, QString sDeviceName);
typedef void(*DestroyLogWidget)(QWidget* pWidget);

class CLogOper : public QObject
{
	Q_OBJECT
public:
	static CLogOper& instance()
	{
		static CLogOper instance;
		return instance;
	}

	void addMsg(SExecLog sExecLog);//添加日志
	QWidget* createLogWidget(QString sDevName);//创建一个日志控件指针 sDevName:传空表示这个日志控件需要显示全部设备日志,当只需要管理个别设备的日志时，传入设备名List，以逗号分隔
	void destroyLogWidget(QWidget* widget);
	
	void setModuleName(QString sName);

private:
	CLogOper();
	~CLogOper();
	QString m_sModuleName;
	QLibrary* m_pLibrary;
	AddMsg m_lpAddMsg = nullptr;
	CreateLogWidget m_lpCreateLogWidget = nullptr;
	DestroyLogWidget m_lpDestroyLogWidget = nullptr;
};
#endif